home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / DEMOS / DEMO4.ARC / !Demo4 / c / simu2 < prev    next >
Text File  |  1992-02-10  |  4KB  |  180 lines

  1. /******************************************************************************
  2. *                                                                             *
  3. *    grp.c                                                                    *
  4. *                                                                             *
  5. ******************************************************************************/
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <math.h>
  10. #include <swis.h>
  11. #include <os.h>
  12. #include <bbc.h>
  13. #include "GrpLib.h"
  14. #include "extern.h"
  15.  
  16. #define  tmax 10000
  17.  
  18. int xorg = 160,yorg = 128,dist = 640;
  19.  
  20. int ra,rs,rt,x,y,z,v;
  21.  
  22. /*****************************************************************************/
  23.  
  24. void reset(void)
  25. {
  26.   ra = 0; rs = 0; rt = 0;
  27.   x = 0; y = 0; z = 0; v = 0;
  28. }
  29.  
  30. /*****************************************************************************/
  31.  
  32. int main()
  33. {
  34.   int  time=0;
  35.   int  msx,msy,msbut,msorgx,msorgy;
  36.   int  kbbut;
  37.   int  stp=2;
  38.   int  collision;
  39.   int  cont=1;
  40.  
  41.   ObjTab  **table;
  42.  
  43.   Object  *obs,*hor,*obj,*plane0;
  44.   Envi    *envi;
  45.  
  46.   Object  *sol1,*sol2,*sol3,*sol4;
  47.   Sol     sold1,sold2,sold3,sold4;
  48.   char    *spr;
  49.   int     *alt;
  50.  
  51.   Object  *tower;
  52.  
  53.   int     t;
  54.   signed char dra,drs,drt,dv;
  55.   signed char traject[tmax][4];
  56.   int     pra,prs,prt,px,py,pz,pv;
  57.  
  58. /***** init grp tools *****/
  59.  
  60.   InitGrp();
  61.   Change2DParm(0,0,319,255);
  62.   Change3DParm(xorg,yorg,dist); 
  63.  
  64. /***** init object table *****/
  65.  
  66.   table = InitPlot(10);
  67.  
  68. /***** set observer and envirronement *****/
  69.  
  70.   obs  = MakeObj("",                    NULL,0);
  71.   PlaceObj(obs,0,0,0,-3000,200,-2500);
  72.  
  73.   envi = MakeEnvi(1, 0, 0x50);
  74.   MkVec4(envi->DirecSrc[0],   128,   128,   128,      0);
  75.   MkVec4(envi->PonctSrc[0],     0,     0,  2000, 100000);
  76.  
  77. /***** set horizon *****/
  78.  
  79.   hor  = MakeObj("",                    NULL,0);
  80.   PlaceObj(hor,0,0,0,0,0,0);
  81.  
  82. /***** load fractal mountains *****/
  83.  
  84.   sol1 = MakeObj("",                    NULL,0);
  85.   sol2 = MakeObj("",                    NULL,0);
  86.   sol3 = MakeObj("",                    NULL,0);
  87.   sol4 = MakeObj("",                    NULL,0);
  88.   AddObject(table,sol1,PlotSol,CollisionSol,1,&sold1);  
  89.   AddObject(table,sol2,PlotSol,CollisionSol,1,&sold2);  
  90.   AddObject(table,sol3,PlotSol,CollisionSol,1,&sold3);  
  91.   AddObject(table,sol4,PlotSol,CollisionSol,1,&sold4);  
  92.   PlaceObj(sol1,   0,0,0,     0,   0,     0);
  93.   PlaceObj(sol2,   0,0,0, 30000,   0, 40000);
  94.   PlaceObj(sol3,   0,0,0,-20000,   0, 10000);
  95.   PlaceObj(sol4,   0,0,0,  5000,   0,-30000);
  96.  
  97.   spr = (char *)load("<GrpObj$Dir>.GrndSpr");
  98.   alt = (int  *)load("<GrpObj$Dir>.GrndAlt8");
  99.   InitSol(&sold1,spr,alt,40,40);
  100.   InitSol(&sold2,spr,alt,20,20);
  101.   InitSol(&sold3,spr,alt,30,30);
  102.   InitSol(&sold4,spr,alt,20,20);
  103.  
  104. /***** load tower object *****/
  105.  
  106.   tower  = MakeObj("<GrpObj$Dir>.CtrlTwr", SCH,0);
  107.   AddObject(table,tower ,PlotObj,        NULL,0,NULL);  
  108.   PlaceObj(tower,0,0,0,-3000,0,0);
  109.  
  110. /***** main loop  of simu *****/
  111.  
  112.   ReadMouse(&msorgx,&msorgy,&msbut);
  113.   v=0;
  114.   obj=obs;
  115.  
  116.   
  117.   t=0;
  118.  
  119.   while(cont) {
  120.    
  121.     dra=0;drs=0;drt=0;dv=0;
  122.  
  123. /*    SetTxtCurPos(0,0); printf("%d",GetClock()-time);*/
  124.     SetTxtCurPos(0,0); printf("%d %d %d %d %d",dra,drs,drt,dv,t);
  125. /*    time = GetClock();*/
  126.  
  127.     PlotHorizon(envi,obj,hor);
  128.     Plot(table,envi,obj);
  129.  
  130.     SwapView(0x00FF);
  131.  
  132.     ReadMouse(&msx,&msy,&msbut);
  133.     msx-=msorgx;
  134.     msy-=msorgy;
  135.  
  136.     kbbut = Inkey();
  137.  
  138.  
  139.     rt = (drt = msx*stp>>6);
  140.     rs = (drs = msy*stp>>7); 
  141.     if (msbut==0x01<<2) ra= (dra =  stp*3);
  142.     if (msbut==0x01<<0) ra= (dra = -stp*3);
  143.     if (msbut==0x01<<1) {
  144.       reset();
  145.     }
  146.     switch (kbbut) {
  147.      case '+' : v+=5; dv =  5; break;
  148.      case '-' : v-=5; dv = -5; break;
  149.      case '6' : x+=50; break;
  150.      case '4' : x-=50; break;
  151.      case '8' : z+=50; break;
  152.      case '2' : z-=50; break;
  153.      case 'o' : obj = obs; break;
  154.      case 's' : obj = plane0; v=0; break;
  155.      case 'b' : cont=0; break;
  156.      case ' ' : return(0);
  157.     }
  158.  
  159.     MoveObj(obs, ra, rs, rt, v);ra=0;
  160.  
  161.     collision = CollisionHorizon(obs,hor);
  162.     if (!collision) collision = Collision(table,obs);
  163.     if ( collision) {
  164.       obs->Org[1] = collision + 200;
  165.       reset();
  166.       SetTxtCurPos(5,0);
  167.       printf("collision%c",0x07);
  168.     }
  169.  
  170.     traject[t][0] = dra; traject[t][1] = drs; traject[t][2] = drt;
  171.     traject[t][3] =  dv;
  172.     t++;
  173.  
  174.   }
  175.  
  176.   SaveTraject("<Demo4$Dir>.traject",traject,t);
  177.   SetTxtCurPos(0,0); printf("%d",t);
  178.  
  179. }
  180.